package com.itheima.health.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.RedisConst;
import com.itheima.health.service.OrderService;
import com.itheima.health.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;

import java.util.Iterator;
import java.util.Set;


/**
 * @author ：seanyang
 * @date ：Created in 2019/6/10
 * @description ：任务调度类
 * @version: 1.0
 */
@Service
public class ClearImageJob {

	@Autowired
	private JedisPool jedisPool;
	@Reference
	private OrderService orderService;
	//    定义清理图片的任务
	public void clearImageJob() {
		try {
			orderService.deleteCron(DateUtils.parseDate2String(DateUtils.getLastDay4LastMonth()));
			System.out.println("定时清理>>>>>>>");
		} catch (Exception e) {
			e.printStackTrace();
		}

//        System.out.println("定时清理>>>>>>>");
	}
	/**
	 * 定义清理图片的任务
	 */
//	public void clearImageJob(){
//			try{
//				System.out.println("clearImageJob......jedisPool:"+jedisPool!=null +" getResource:"+jedisPool.getResource());
//				// 获取两个数据差集
//			Set<String> set = jedisPool.getResource().sdiff(RedisConst.SETMEAL_PIC_DB_RESOURCES,
//				RedisConst.SETMEAL_PIC_RESOURCES);
//			if (set == null){
//				System.out.println("clearImageJob......set is null");
//				return;
//			}
//			Iterator<String> iterator = set.iterator();
//			while (iterator.hasNext()){
//				String picName = iterator.next();
//				QiniuUtils.deleteFileFromQiniu(picName);
//				jedisPool.getResource().srem(RedisConst.SETMEAL_PIC_RESOURCES,picName);
//				System.out.println("clearImageJob......del:"+picName);
//			}
//		}catch(Exception e){
//		    e.printStackTrace();
//		}
//
//	}
}
